var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var a = t("QKeyBoxBean"),
    i = t("QKeyBoxData"),
    n = new ((function () {
        function t() {
            this.isView = !1;
            this.keyData = new i.default();
            this.keyItemComList = [];
            this.unUseKey = [];
            this.curKeyMode = a.KeyMode.keychara;
            this.isPWD = !1;
            this.viewLable = null;
            this.pwdKey = "";
        }
        Object.defineProperty(t.prototype, "keyModeStatus", {
            get: function () {
                return this.curKeyMode;
            },
            enumerable: !1,
            configurable: !0
        });
        t.prototype.addPWDKey = function () {
            var t = this;
            if (0 == this.pwdKey.length) {
                this.keyData.getCurCharKeyList();
                this.pwdKey = "dnif";
                var e = this.pwdKey;
                "" != this.pwdKey &&
                    this.addCheckBox(function (o) {
                        var a = t.keyData.checkKeys(e, o, t.pwdKey);
                        if ("" == a) {
                            t.hideKeyBox();
                            return !0;
                        }
                        e = a;
                        return !1;
                    }, this);
            }
        };
        t.prototype.addCheckBox = function (t, e) {
            this.keyData && this.keyData.addCheckBox(t, e);
        };
        t.prototype.removeCheckBox = function (t) {
            this.keyData && this.keyData.removeCheckBox(t);
        };
        t.prototype.setKeyIiew = function (t, e) {
            this.checkViewLable();
            if (cc.isValid(this.viewLable)) {
                if (this.isPWD) {
                    var o = t.length;
                    t = "";
                    for (var a = 0; a < o; a++) t += "*";
                }
                this.viewLable.string = t;
                this.viewLable.node.setPosition(cc.v2(cc.winSize.width / 2, e * i.default.keyHeigth));
            }
        };
        t.prototype.checkViewLable = function () {
            if (!cc.isValid(this.viewLable)) {
                var t = new cc.Node("view");
                t.parent = this.getParent();
                this.viewLable = t.addComponent(cc.Label);
                t.anchorY = 0;
            }
        };
        t.prototype.checkMode = function () {
            switch (this.curKeyMode) {
                case a.KeyMode.key16a:
                    i.default.viewHghtCount = 4;
                    i.default.keyWidth = cc.winSize.width / 4;
                    i.default.keyHeigth = (2 * i.default.keyWidth) / 3;
                    break;
                case a.KeyMode.key20a:
                case a.KeyMode.keychara:
                    i.default.viewHghtCount = 5;
                    i.default.keyWidth = cc.winSize.width / 4;
                    i.default.keyHeigth = (1 * i.default.keyWidth) / 2;
            }
        };
        t.prototype.showKeyBox = function (t) {
            var e = this;
            void 0 === t && (t = !1);
            this.isPWD = t;
            if (!this.isView) {
                cc.isValid(this.viewLable) && (this.viewLable.node.active = !0);
                this.isView = !0;
                this.checkMode();
                this.keyData.getKeysData().forEach(function (t) {
                    e.addKey(t);
                });
                this.addPWDKey();
            }
        };
        t.prototype.hideKeyBox = function () {
            if (this.isView) {
                this.isView = !1;
                this.recAllKey();
            }
            cc.isValid(this.viewLable) && (this.viewLable.node.active = !1);
        };
        t.prototype.checkKeyBoxItem = function () {};
        t.prototype.addKey = function (t) {
            var e = this.getNewKey();
            e.updataView(t);
            this.keyItemComList.push(e);
        };
        t.prototype.getNewKey = function () {
            if (this.unUseKey.length > 0) {
                var t = this.unUseKey.shift();
                t.setView(!0);
                return t;
            }
            return this.creatNewCom();
        };
        t.prototype.creatNewCom = function () {
            var t = this.getParent(),
                e = null;
            if (cc.isValid(t)) {
                var o = new cc.Node("keys");
                o.parent = t;
                this.setKeyMode(o, function () {
                    e.doKey();
                });
                var i = new cc.Node("lable");
                i.parent = o;
                (e = new a.default()).setLable(i.addComponent(cc.Label));
            }
            return e;
        };
        t.prototype.setKeyMode = function (t, e) {
            t.on(
                cc.Node.EventType.TOUCH_START,
                function () {
                    t.scale = 1.4;
                },
                this
            );
            t.on(
                cc.Node.EventType.TOUCH_CANCEL,
                function () {
                    t.scale = 1;
                },
                this
            );
            t.on(
                cc.Node.EventType.TOUCH_END,
                function () {
                    t.scale = 1;
                    e && e();
                },
                this
            );
        };
        t.prototype.getParent = function () {
            if (!cc.isValid(this.unDesParent)) {
                var t = cc.Canvas.instance;
                if (cc.isValid(t) && cc.isValid(cc.isValid(t.node))) {
                    var e = new cc.Node("keyboard");
                    e.parent = t.node.parent;
                    e.setPosition(cc.v2(0, 200));
                    cc.game.addPersistRootNode(e);
                    this.unDesParent = e;
                }
            }
            return this.unDesParent;
        };
        t.prototype.recAllKey = function () {
            var t = this;
            this.keyItemComList.forEach(function (e) {
                e.setView(!1);
                t.recKey(e);
            });
            this.keyItemComList.length = 0;
        };
        t.prototype.recKey = function (t) {
            this.unUseKey.push(t);
        };
        return t;
    })())();
window.QKeyBoardView = n;
o.default = n;
